package com.yy.user.controller;

import com.yy.user.User;
import com.yy.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yangyao
 * @Description: User控制器
 * @date 2018/8/23 14:31
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public User add(@RequestBody User user) {
        return this.userService.save(user);
    }

    @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
    public void del(@PathVariable("id")Long id) {
        this.userService.delete(id);
    }

    @RequestMapping(value = "/findByUsername", method = RequestMethod.GET)
    public User findByUsername(String username) {
        return this.userService.findByUsername(username);
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<User> list() {
        return this.userService.findAll();
    }
}
